#include "stdafx.h"
#include "CppUnitTest.h"

#include "TestFiles.h"

#include "ImageExptLib.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace PluginICProcStepsTest
{
	TEST_CLASS(ImageExptLibTest)
	{
		ImageExptLib *_imageExptLib;

	public:
		TEST_METHOD_INITIALIZE(InitImageExptLibTest)
		{
			_imageExptLib = new ImageExptLib();
		}

		TEST_METHOD_CLEANUP(DeinitImageExptLibTest)
		{
			if (_imageExptLib != '\0')
				delete _imageExptLib;
			_imageExptLib = '\0';
		}

		TEST_METHOD(CreateImageExptLibTest)
		{
			Assert::IsNotNull(_imageExptLib);
		}

		TEST_METHOD(CreateDefaultIEFTest)
		{
			Assert::IsTrue(ImageExptLib::CreateDefaultImageExptFile(TestFiles::UnitTestIEFwStr, "Unit Test"));
		}

		TEST_METHOD(ConvertStrTest)
		{
			const char *destStr;
			char destbuffStr[ImageExptLib::MaxPathFileNameLen];

			Assert::IsNotNull(destStr = ImageExptLib::ConvertwStrToStr(destbuffStr, (size_t) (sizeof(destbuffStr) / sizeof(char)), TestFiles::UnitTestIEFwStr, ImageExptLib::MaxPathFileNameLen));
			Assert::AreEqual(TestFiles::UnitTestIEFStr, destStr);

			const wchar_t *destwStr;
			wchar_t destbuffwStr[ImageExptLib::MaxPathFileNameLen];

			Assert::IsNotNull(destwStr = ImageExptLib::ConvertStrTowStr(destbuffwStr, (size_t) (sizeof(destbuffwStr) / sizeof(wchar_t)), TestFiles::UnitTestIEFStr, ImageExptLib::MaxPathFileNameLen));
			Assert::AreEqual(TestFiles::UnitTestIEFwStr,destwStr); 
		}

		TEST_METHOD(ConvertStrFailTest)
		{
			char destbuffStr[ImageExptLib::MaxPathFileNameLen];
			wchar_t destbuffwStr[ImageExptLib::MaxPathFileNameLen];
			const char *destStr = '\0';
			const wchar_t *destwStr = '\0';

						//bad output params
			Assert::IsNull(destStr = ImageExptLib::ConvertwStrToStr('\0', (size_t) (sizeof(destbuffStr) / sizeof(char)), TestFiles::UnitTestIEFwStr, ImageExptLib::MaxPathFileNameLen));
			Assert::IsNull(destwStr = ImageExptLib::ConvertStrTowStr('\0', (size_t) (sizeof(destbuffwStr) / sizeof(wchar_t)), TestFiles::UnitTestIEFStr, ImageExptLib::MaxPathFileNameLen));
						//bad input params
			Assert::IsNull(destStr = ImageExptLib::ConvertwStrToStr(destbuffStr, (size_t) (sizeof(destbuffwStr) / sizeof(wchar_t)), '\0', ImageExptLib::MaxPathFileNameLen));
			Assert::IsNull(destwStr = ImageExptLib::ConvertStrTowStr(destbuffwStr, (size_t) (sizeof(destbuffwStr) / sizeof(wchar_t)), '\0', ImageExptLib::MaxPathFileNameLen));
						//too small output buff params - ASSERTS, in production it should fail
			//CFIXCC_ASSERT_EQUALS(true, (destStr = ImageExptLib::ConvertwStrToStr(destbuffStr, (size_t) 10, ImageExptLibTest::UnitTestIEFwStr, ImageExptLib::MaxPathFileNameLen)) != '\0');
			//CFIXCC_ASSERT_EQUALS(false, (destwStr = ImageExptLib::ConvertStrTowStr(destbuffwStr, (size_t) 10, ImageExptLibTest::UnitTestIEFStr, ImageExptLib::MaxPathFileNameLen)) != '\0');
						//too big input string		
			Assert::IsNull(destStr = ImageExptLib::ConvertwStrToStr(destbuffStr, (size_t) (sizeof(destbuffwStr) / sizeof(wchar_t)), TestFiles::UnitTestIEFwStr, 10));
			Assert::IsNull(destwStr = ImageExptLib::ConvertStrTowStr(destbuffwStr, (size_t) (sizeof(destbuffwStr) / sizeof(wchar_t)), TestFiles::UnitTestIEFStr, 10));
		}

		TEST_METHOD(CopyFileIsExistTest)
		{
			if (ImageExptLib::IsFileExist(TestFiles::UnitTestCopyFilewStr))
				Assert::IsTrue(ImageExptLib::DeleteImageFile( TestFiles::UnitTestCopyFilewStr));

			Assert::IsTrue( ImageExptLib::CopyImageFile( TestFiles::UnitTestCopyFilewStr, TestFiles::UnitTestIEFwStr));
			Assert::IsTrue( ImageExptLib::IsFileExist(TestFiles::UnitTestCopyFilewStr));
			Assert::IsTrue( ImageExptLib::DeleteImageFile( TestFiles::UnitTestCopyFilewStr));

			Assert::IsFalse( ImageExptLib::DeleteImageFile( '\0'));
			Assert::IsFalse( ImageExptLib::DeleteImageFile( L"xxxx" ));

			Assert::IsFalse( ImageExptLib::IsFileExist('\0'));
			Assert::IsFalse( ImageExptLib::IsFileExist(L"xxxx"));

			Assert::IsFalse( ImageExptLib::CopyImageFile( TestFiles::UnitTestCopyFilewStr, '\0'));
			Assert::IsFalse( ImageExptLib::CopyImageFile( '\0', TestFiles::UnitTestIEFwStr));
			Assert::IsFalse( ImageExptLib::CopyImageFile( '\0', '\0'));
			Assert::IsFalse( ImageExptLib::CopyImageFile( TestFiles::UnitTestCopyFilewStr, L"xxxx"));
		}

	};
}